import cv2 as cv
import numpy as np


def find_contours_func():
    src_img = np.zeros((320, 640, 3), np.uint8)
    src_img[50:100, 50:100] = [50, 100, 80]
    cv.circle(src_img, (320, 180), 25, (255, 0, 0), 10)
    cv.rectangle(src_img, (400, 100), (580, 200), (0, 255, 0), 5)
    cv.imshow('source image', src_img)

    gray_img = cv.cvtColor(src_img, cv.COLOR_BGR2GRAY)

    ret, binary_img = cv.threshold(gray_img, 10, 255, cv.THRESH_BINARY)
    cv.imshow('binary_image', binary_img)

    contours, hie = cv.findContours(binary_img, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
    cv.drawContours(src_img, contours, -1, (0, 0, 255), 3)

    cv.imshow('out image', src_img)

    m = cv.moments(contours[0])
    print(m)
    cv.waitKey(0)


def main():
    find_contours_func()


if __name__ == '__main__':
    main()

